package com.brand.prisd.sp;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;

/**
 * Created by HJ on 2018/12/11.
 */
public class MySharedPreferences {

    private static final String NAME = "SP";
    private static final String Default_String = null;
    private static final int Default_Int = -1;
    private static final Boolean Default_Boolean = false;
    private static SharedPreferences sharedPreferences;

    public Boolean putBoolean(String key, Boolean val) {
        return sharedPreferences.edit().putBoolean(key, val).commit();
    }

    public Boolean getBoolean(String key) {
        return sharedPreferences.getBoolean(key, false);
    }

    @NonNull
    public static MySharedPreferences creatByName(@NonNull Context context, @NonNull String name) {
        sharedPreferences = context.getSharedPreferences(name, Context.MODE_PRIVATE);
        return new MySharedPreferences();
    }

    @NonNull
    public static MySharedPreferences Build(@NonNull Context context) {
        sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        return new MySharedPreferences();
    }

    public Boolean putString(@NonNull String key, String val) {
        return sharedPreferences.edit().putString(key, val).commit();
    }

    public String getString(@NonNull String key, String def) {
        return sharedPreferences.getString(key, def);
    }

    public String getString(@NonNull String key) {
        return sharedPreferences.getString(key, Default_String);
    }

    public Boolean putInt(@NonNull String key, int value) {
        return sharedPreferences.edit().putInt(key, value).commit();
    }

    public int getInt(@NonNull String key, int defValue) {
        return sharedPreferences.getInt(key, defValue);
    }

    public Boolean putLong(@NonNull String key, long value) {
        return sharedPreferences.edit().putLong(key, value).commit();
    }

    public long getLong(@NonNull String key, long defValue) {
        return sharedPreferences.getLong(key, defValue);
    }
}
